using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vms.Web.Models;

namespace Vms.Web.Areas.Lib.Controllers
{   
    public class ContentImgController : Controller
    {
        private VmsWebContext context = new VmsWebContext();


        //
        // GET: /LIB_CONTENT_IMG/

        public ViewResult Index()
        {
            return View(context.LIB_CONTENT_IMGS.ToList());
        }

        //
        // GET: /LIB_CONTENT_IMG/Details/5

        public ViewResult Details(int id)
        {
            LIB_CONTENT_IMG lib_content_img = context.LIB_CONTENT_IMGS.Single(x => x.Id == id);
            return View(lib_content_img);
        }

        //
        // GET: /LIB_CONTENT_IMG/Create

        public ActionResult Create()
        {
            // Dua danh sach 1 -> vao danh sach hien thi dropdownlist
            List<SelectListItem> list = new List<SelectListItem>();
            for (int i = 1; i <= 10; ++i)
            {
                SelectListItem item = new SelectListItem();
                item.Text = "" + i;
                item.Value = "" + i;
                list.Add(item);
            }
            // Dua danh sach len view
            ViewBag.List = list;
            return View();
        } 

        //
        // POST: /LIB_CONTENT_IMG/Create

        [HttpPost]
        public ActionResult Create(LIB_CONTENT_IMG lib_content_img)
        {
            if (ModelState.IsValid)
            {
                context.LIB_CONTENT_IMGS.Add(lib_content_img);
                context.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(lib_content_img);
        }
        
        //
        // GET: /LIB_CONTENT_IMG/Edit/5
 
        public ActionResult Edit(int id)
        {
            LIB_CONTENT_IMG lib_content_img = context.LIB_CONTENT_IMGS.Single(x => x.Id == id);
            return View(lib_content_img);
        }

        //
        // POST: /LIB_CONTENT_IMG/Edit/5

        [HttpPost]
        public ActionResult Edit(LIB_CONTENT_IMG lib_content_img)
        {
            if (ModelState.IsValid)
            {
                context.Entry(lib_content_img).State = EntityState.Modified;
                context.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(lib_content_img);
        }

        //
        // GET: /LIB_CONTENT_IMG/Delete/5
 
        public ActionResult Delete(int id)
        {
            LIB_CONTENT_IMG lib_content_img = context.LIB_CONTENT_IMGS.Single(x => x.Id == id);
            return View(lib_content_img);
        }

        //
        // POST: /LIB_CONTENT_IMG/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            LIB_CONTENT_IMG lib_content_img = context.LIB_CONTENT_IMGS.Single(x => x.Id == id);
            context.LIB_CONTENT_IMGS.Remove(lib_content_img);
            context.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                context.Dispose();
            }
            base.Dispose(disposing);
        }
        public ActionResult SearchContentImg(string searchString)
        {
            var lib_content_imgs = from m in context.LIB_CONTENT_IMGS
                      select m;

            if (!String.IsNullOrEmpty(searchString))
            {
                lib_content_imgs = lib_content_imgs.Where(s => s.Name.Contains(searchString));
            }

            return View(lib_content_imgs);
        }
    }
}